namespace Adge.Common
{
    using System;
    using System.Text;

    public class CalUtility
    {
        public CalUtility(string calStr)
        {
            this.iCurr = 0;
            this.iCount = 0;
            this.StrB = new StringBuilder(calStr.Trim());
            this.iCount = Encoding.Default.GetByteCount(calStr.Trim());
        }

        public bool Compare(string str1, string str2)
        {
            return (this.getPriority(str1) >= this.getPriority(str2));
        }

        public string getItem()
        {
            if (this.iCurr == this.iCount)
            {
                return "";
            }
            char ch1 = this.StrB[this.iCurr];
            bool flag1 = this.IsNum(ch1);
            if (!flag1)
            {
                this.iCurr++;
                return ch1.ToString();
            }
            string text1 = "";
            while ((this.IsNum(ch1) == flag1) && (this.iCurr < this.iCount))
            {
                ch1 = this.StrB[this.iCurr];
                if (this.IsNum(ch1) != flag1)
                {
                    return text1;
                }
                text1 = text1 + ch1;
                this.iCurr++;
            }
            return text1;
        }

        public int getPriority(string str)
        {
            if (str.Equals(""))
            {
                return -1;
            }
            if (!str.Equals("("))
            {
                if (str.Equals("+") || str.Equals("-"))
                {
                    return 1;
                }
                if (str.Equals("*") || str.Equals("/"))
                {
                    return 2;
                }
                if (str.Equals(")"))
                {
                    return 0;
                }
            }
            return 0;
        }

        public bool IsNum(char c)
        {
            if (((c >= '0') && (c <= '9')) || (c == '.'))
            {
                return true;
            }
            return false;
        }

        public bool IsNum(string c)
        {
            if (!c.Equals("") && (((c[0] >= '0') && (c[0] <= '9')) || (c[0] == '.')))
            {
                return true;
            }
            return false;
        }


        private int iCount;
        private int iCurr;
        private StringBuilder StrB;
    }
}

